package ui

import applicationModel.AlmanaquePlantas
import dominio.Planta
import org.uqbar.arena.layout.ColumnLayout
import org.uqbar.arena.layout.HorizontalLayout
import org.uqbar.arena.widgets.Button
import org.uqbar.arena.widgets.Panel
import org.uqbar.arena.widgets.tables.Column
import org.uqbar.arena.widgets.tables.Table
import org.uqbar.arena.windows.Dialog
import org.uqbar.arena.windows.WindowOwner

class AlmanaquePlantasWindow extends Dialog<AlmanaquePlantas> {

	new(WindowOwner parent, AlmanaquePlantas almanaque) {
		super(parent, almanaque)
		modelObject.search()
	}

	override def createMainTemplate(Panel mainPanel) {
		title = "Almanaque de Plantas"

		super.createMainTemplate(mainPanel)

		this.createResultsGrid(mainPanel)
		this.createGridActions(mainPanel)
	}

	override protected createFormPanel(Panel mainPanel) {
		var searchFormPanel = new Panel(mainPanel)
		searchFormPanel.setLayout(new ColumnLayout(2))

	}

	def protected createResultsGrid(Panel mainPanel) {
		var table = new Table<Planta>(mainPanel, typeof(Planta))
		table.heigth = 200
		table.width = 450
		table.bindItemsToProperty("resultados")
		this.describeResultsGrid(table)
	}

	def void describeResultsGrid(Table<Planta> table) {
		new Column<Planta>(table) //
		.setTitle("Nombre").setFixedSize(150).bindContentsToProperty("nombre")

		new Column<Planta>(table) //
		.setTitle("Tipo").setFixedSize(150).bindContentsToProperty("tipo")

		new Column<Planta>(table).setTitle("Puntos Daño").setFixedSize(50).bindContentsToProperty("puntosDanio")

		new Column<Planta>(table) //
		.setTitle("Defensa").setFixedSize(100).bindContentsToProperty("capacidadDefensiva")

	}

	//override protected addActions(Panel actionsPanel) {
	//val botonvolver = new Button(actionsPanel).setAsDefault.setCaption("Tablero")
	//botonvolver.onClick[|cancel]
	//}
	def createGridActions(Panel mainPanel) {
		var actionsPanel = new Panel(mainPanel)
		actionsPanel.setLayout(new HorizontalLayout)
		val botonvolver = new Button(actionsPanel).setAsDefault.setCaption("Tablero")
		botonvolver.onClick[|cancel]
	}
}
